﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Raven.Client;
using Genrsis.WorkitemTracking.Domain;

namespace Genrsis.WorkitemTracking.Web.Controllers
{
    public class TestingController : ControllerBase
    {
        public TestingController(IDocumentStore documentStore)
            : base(documentStore)
        {
        }

        [HttpGet]
        public ActionResult Actions(string message = "")
        {
            ViewBag.Message = message;

            ViewBag.Actions = new[] 
            {
                "CreateWorkitemStatuses"
            };

            return View();
        }

        [HttpPost]
        public ActionResult CreateWorkitemStatuses()
        {
            using (var session = DocumentStore.OpenSession())
            {
                session.Store(new Status { Name = "New", AppliesTo = new[] { StatusAppliesToOption.Workitem } });
                session.Store(new Status { Name = "Working-on", AppliesTo = new[] { StatusAppliesToOption.Workitem } });
                session.Store(new Status { Name = "Completed", AppliesTo = new[] { StatusAppliesToOption.Workitem } });
                session.Store(new Status { Name = "Closed", AppliesTo = new[] { StatusAppliesToOption.Workitem } });

                session.SaveChanges();
            }

            return ReturnToActions("Created workitem statuses.");
        }

        private ActionResult ReturnToActions(string message)
        {
            return RedirectToAction("Actions", new { Message = message });
        }
    }
}
